package reservator.common;

import java.io.Serializable;

/**
 * Represent a transport of the reservator system
 * @author Pascal Cuisinaud, Thomas Di'Meco
 */
public class Transport implements Serializable
{
    private static final long serialVersionUID = 1L;
    
    private int    id;
    private String type;
    private String name;
    private int    capacity;
    
    /**
     * Default constructor
     */
    public Transport () {}
    
    /**
     * Construct a transport with the given informations
     * @param id        The transport id
     * @param type      The transport type
     * @param name      The transport name
     * @param capacity  The transport capacity
     */
    public Transport (int id, String type, String name, int capacity)
    {
        this.id = id;
        this.type = (type == null ? null : type.toUpperCase().trim());
        this.name = name;
        this.capacity = capacity;
    }
    
    /**
     * Equals method for Transport
     * @param object to be checked
     * @return true if object equals this Transport, false otherwise
     */
    @Override
    public boolean equals (Object obj)
    {
        if (this == obj) return true;
        if (!(obj instanceof Transport)) return false;
        
        Transport other = (Transport) obj;
        
        return (this.id == other.id) &&
               this.type.equals(other.type) &&
               this.name.equals(other.name) &&
               this.capacity == other.capacity;
    }
    
    /**
     * ToString method
     * @return A string that contains the class intance's informations
     */    
    @Override
    public String toString ()
    {
        return "Transport [id=" + id + ", type=" + type + ", name=" + name
                + ", capacity=" + capacity + "]";
    }
    
    /**
     * Create a Transport from a String which contains transport informations. (reverse of toString())
     * @param A string that contains the class intance's informations
     */    
    public void createTransport (String s)
    {
        // extracting data from the string and use setters to put it in the
        // transport
        setId(Integer.valueOf(s.split(",")[0].split("=")[1]));
        setType(s.split(",")[1].split("=")[1]);
        setName(s.split(",")[2].split("=")[1]);
        setCapacity(Integer.valueOf(s.split(",")[3].split("=")[1].split("]")[0]));
    }
    
    // ************* Getters and Setters *************
    public int getId ()
    {
        return id;
    }

    public void setId (int id)
    {
        this.id = id;
    }

    public String getType ()
    {
        return type;
    }

    public void setType (String type)
    {
        this.type = type.toUpperCase().trim();
    }

    public String getName ()
    {
        return name;
    }

    public void setName (String name)
    {
        this.name = name;
    }

    public int getCapacity ()
    {
        return capacity;
    }

    public void setCapacity (int capacity)
    {
        this.capacity = capacity;
    }
    // **********************************************

}
